package cn.xmkeshe.back.impl;

import cn.xmkeshe.back.ICustomerServiceBack;
import cn.xmkeshe.dao.ICustomerDao;
import cn.xmkeshe.model.Customer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ICustomerServiceBackImpl implements ICustomerServiceBack {

  @Resource
  private ICustomerDao iCustomerDao;

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> listSplit(int currentPage, int lineSize) {
    Map<String,Object> result = new HashMap<String, Object>();
    result.put("start",(currentPage-1)*lineSize);
    result.put("lineSize",lineSize);
    Map<String,Object> map = new HashMap<String, Object>(result);
    map.put("data",iCustomerDao.findAllBySplit(result));
    map.put("count",iCustomerDao.getAllCount());
    return map;
  }

  @Override
  @Transactional(readOnly = true)
  public Map<String, Object> findByName(int currentPage, int lineSize, String name) {
    Map<String,Object> map = new HashMap<String, Object>();
    map.put("data",iCustomerDao.findByName((currentPage-1)*lineSize, lineSize,name));
    map.put("count",iCustomerDao.getAllCount());
    return map;
  }

  @Override
  public boolean delete(String cuid) {
    return iCustomerDao.delete(cuid);
  }

}
